package Login.servlet;

import Login.Service.BookService;
import Login.entity.Book;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "editSaveServlet",urlPatterns = "/save")
public class editSaveServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Book book = new Book();
        book.setBookId(req.getParameter("bookId"));
        book.setBookName(req.getParameter("bookName"));
        book.setBookStatus(req.getParameter("bookStatus"));

        BookService bookService = new BookService();
        if (!bookService.hasSession(req.getSession(), resp)) {
            return;
        }
        int update = bookService.update(book);
        if (update>0) {
            resp.sendRedirect("list");
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }
}
